```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx URL重写与重定向指南 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        .hero-image {
            background: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.3)), url('https://images.unsplash.com/photo-1620712943543-bcc4688e7485?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80');
            background-size: cover;
            background-position: center;
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-left: 4px solid #4299e1;
            padding: 1.5rem;
            font-family: 'Courier New', Courier, monospace;
            border-radius: 0 4px 4px 0;
            position: relative;
        }
        .code-block:before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 30px;
            background-color: rgba(255,255,255,0.1);
            border-radius: 4px 4px 0 0;
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 6px;
            background: linear-gradient(90deg, #4299e1, #38b2ac);
            opacity: 0.3;
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover:after {
            height: 100%;
            opacity: 0.1;
        }
        .card {
            transition: all 0.3s ease;
            border: 1px solid rgba(210, 218, 226, 0.5);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
            border-color: rgba(66, 153, 225, 0.5);
        }
        .section-divider {
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(66, 153, 225, 0.5), transparent);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-image min-h-screen flex items-center justify-center text-white">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">Nginx URL 重写与重定向</h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto">掌握网站架构的核心技术，优化用户体验与SEO表现</p>
            <div class="flex justify-center space-x-4">
                <a href="#url-rewrite" class="px-6 py-3 bg-blue-600 hover:bg-blue-700 rounded-md transition duration-300 flex items-center">
                    <i class="fas fa-pen-fancy mr-2"></i> URL重写
                </a>
                <a href="#url-redirect" class="px-6 py-3 bg-gray-800 hover:bg-gray-700 rounded-md transition duration-300 flex items-center">
                    <i class="fas fa-directions mr-2"></i> URL重定向
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16 max-w-5xl">
        <!-- Introduction -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif text-gray-800">在Nginx中配置URL重写和重定向</h2>
            <p class="text-gray-700 mb-4">URL重写和重定向是网站架构中的常见需求，特别是在处理网站迁移、SEO优化以及创建用户友好URL等方面尤为重要。通过合理的配置，可以显著提升网站的可维护性和用户体验。</p>
            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 my-6">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-info-circle text-blue-500 text-xl"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-sm text-blue-700">Nginx的<code class="bg-blue-100 px-1 py-0.5 rounded">rewrite</code>和<code class="bg-blue-100 px-1 py-0.5 rounded">return</code>指令提供了强大的URL操作能力，理解它们的区别和应用场景是高效配置的关键。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- URL Rewrite Section -->
        <section id="url-rewrite" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-pen-fancy text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif text-gray-800">1. URL 重写</h2>
            </div>
            
            <p class="text-gray-700 mb-6">URL重写是指将请求的URL修改为另一个URL以便更好地处理请求。Nginx提供了<code class="bg-gray-100 px-1 py-0.5 rounded">rewrite</code>指令用于URL重写。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="text-xl font-bold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-code mr-2 text-blue-500"></i> 基本语法
                    </h3>
                    <div class="code-block">
                        <pre><code>rewrite regex replacement [flag];</code></pre>
                    </div>
                    <div class="mt-4">
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="bg-gray-100 px-1 py-0.5 rounded">regex</code>：匹配请求URL的正则表达式</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="bg-gray-100 px-1 py-0.5 rounded">replacement</code>：将匹配到的URL替换为的新URL</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="bg-gray-100 px-1 py-0.5 rounded">flag</code>：控制重写行为的标志（可选）</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="text-xl font-bold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-project-diagram mr-2 text-blue-500"></i> 使用场景
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center mt-1 mr-3">
                                <i class="fas fa-search text-blue-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">SEO优化</h4>
                                <p class="text-gray-600 text-sm">将旧的URL重写为新的URL，以保留搜索引擎排名</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center mt-1 mr-3">
                                <i class="fas fa-link text-purple-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">用户友好URL</h4>
                                <p class="text-gray-600 text-sm">将复杂的URL转换为更简洁的URL</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-100 flex items-center justify-center mt-1 mr-3">
                                <i class="fas fa-random text-green-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">处理动态请求</h4>
                                <p class="text-gray-600 text-sm">将动态请求映射到静态内容或不同的处理逻辑</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-laptop-code mr-3 text-blue-500"></i> 配置示例
            </h3>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white p-6 rounded-lg">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">示例1：基本重写</h4>
                    <p class="text-gray-600 mb-4">将<code class="bg-gray-100 px-1 py-0.5 rounded">/old-page</code>重写为<code class="bg-gray-100 px-1 py-0.5 rounded">/new-page</code></p>
                    <div class="code-block">
                        <pre><code>location /old-page {
    rewrite ^/old-page$ /new-page permanent;
}</code></pre>
                    </div>
                    <div class="mt-4 bg-yellow-50 border-l-4 border-yellow-400 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-lightbulb text-yellow-500"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-yellow-700"><code class="bg-yellow-100 px-1 py-0.5 rounded">permanent</code>表示使用301永久重定向状态码，对SEO友好。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">示例2：模式匹配重写</h4>
                    <p class="text-gray-600 mb-4">将<code class="bg-gray-100 px-1 py-0.5 rounded">/demo/</code>开头的URL重写</p>
                    <div class="code-block">
                        <pre><code>location / {
    rewrite ^/demo/(.*)$ /demo/$1 last;
}</code></pre>
                    </div>
                    <div class="mt-4 bg-blue-50 border-l-4 border-blue-400 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-info-circle text-blue-500"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-blue-700"><code class="bg-blue-100 px-1 py-0.5 rounded">last</code>表示重写后停止处理其他重写规则。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Divider -->
        <div class="section-divider my-12"></div>

        <!-- URL Redirect Section -->
        <section id="url-redirect" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-directions text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif text-gray-800">2. URL 重定向</h2>
            </div>
            
            <p class="text-gray-700 mb-6">URL重定向是指将请求的URL转发到另一个URL。Nginx使用<code class="bg-gray-100 px-1 py-0.5 rounded">return</code>指令或<code class="bg-gray-100 px-1 py-0.5 rounded">rewrite</code>指令的重定向标志来实现URL重定向。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="text-xl font-bold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-code mr-2 text-blue-500"></i> 基本语法
                    </h3>
                    <div class="code-block">
                        <pre><code>return code url;</code></pre>
                    </div>
                    <div class="mt-4">
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="bg-gray-100 px-1 py-0.5 rounded">code</code>：HTTP状态码（例如301、302）</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span><code class="bg-gray-100 px-1 py-0.5 rounded">url</code>：重定向的目标URL</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <h3 class="text-xl font-bold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-project-diagram mr-2 text-blue-500"></i> 使用场景
                    </h3>
                    <div class="space-y-4">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center mt-1 mr-3">
                                <i class="fas fa-truck-moving text-blue-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">网站迁移</h4>
                                <p class="text-gray-600 text-sm">将旧的URL重定向到新的URL</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center mt-1 mr-3">
                                <i class="fas fa-lock text-purple-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">协议切换</h4>
                                <p class="text-gray-600 text-sm">将HTTP请求重定向到HTTPS</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-100 flex items-center justify-center mt-1 mr-3">
                                <i class="fas fa-clock text-green-600"></i>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800">临时调整</h4>
                                <p class="text-gray-600 text-sm">临时将某些请求转发到不同的URL</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <h3 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-laptop-code mr-3 text-blue-500"></i> 配置示例
            </h3>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white p-6 rounded-lg">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">示例1：HTTPS强制跳转</h4>
                    <p class="text-gray-600 mb-4">将所有HTTP请求重定向到HTTPS</p>
                    <div class="code-block">
                        <pre><code>server {
    listen 80;
    server_name demo.com;
    return 301 https://$host$request_uri;
}</code></pre>
                    </div>
                    <div class="mt-4 bg-blue-50 border-l-4 border-blue-400 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-info-circle text-blue-500"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-blue-700"><code class="bg-blue-100 px-1 py-0.5 rounded">301</code>是永久重定向的状态码，<code class="bg-blue-100 px-1 py-0.5 rounded">$host$request_uri</code>保留原始请求的主机和URI。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">示例2：页面重定向</h4>
                    <p class="text-gray-600 mb-4">将<code class="bg-gray-100 px-1 py-0.5 rounded">/old-page</code>重定向到<code class="bg-gray-100 px-1 py-0.5 rounded">/new-page</code></p>
                    <div class="code-block">
                        <pre><code>location /old-page {
    return 302 /new-page;
}</code></pre>
                    </div>
                    <div class="mt-4 bg-yellow-50 border-l-4 border-yellow-400 p-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-lightbulb text-yellow-500"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-yellow-700"><code class="bg-yellow-100 px-1 py-0.5 rounded">302</code>是临时重定向的状态码，适用于暂时性的URL变更。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Complete Example Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-file-code text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif text-gray-800">3. 完整配置示例</h2>
            </div>
            
            <p class="text-gray-700 mb-6">以下是一个包含URL重写和重定向的完整Nginx配置示例，涵盖了常见的应用场景：</p>
            
            <div class="card bg-white rounded-lg overflow-hidden">
                <div class="flex items-center bg-gray-800 text-gray-200 px-4 py-3">
                    <div class="flex space-x-2 mr-4">
                        <div class="w-3 h-3 rounded-full bg-red-500"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                    </div>
                    <div class="text-sm">nginx.conf</div>
                </div>
                <div class="code-block">
                    <pre><code>server {
    listen 80;
    server_name demo.com;

    # 重定向 HTTP 到 HTTPS
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name demo.com;

    ssl_certificate /path/to/certificate.crt;
    ssl_certificate_key /path/to/private.key;

    # 将旧页面重定向到新页面
    location /old-page {
        return 301 /new-page;
    }

    # 将 URL 中的 demo 替换为 demo
    location / {
        rewrite ^/demo/(.*)$ /demo/$1 last;
    }
}</code></pre>
                </div>
            </div>
            
            <div class="mt-6 grid md:grid-cols-2 gap-6">
                <div class="bg-blue-50 border-l-4 border-blue-500 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-server text-blue-500"></i>
                        </div>
                        <div class="ml-3">
                            <h4 class="font-medium text-gray-800">第一个server块</h4>
                            <p class="text-sm text-gray-600 mt-1">处理将所有HTTP请求重定向到HTTPS，保证网站通信安全。</p>
                        </div>
                    </div>
                </div>
                <div class="bg-green-50 border-l-4 border-green-500 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lock text-green-500"></i>
                        </div>
                        <div class="ml-3">
                            <h4 class="font-medium text-gray-800">第二个server块</h4>
                            <p class="text-sm text-gray-600 mt-1">处理HTTPS请求，包含URL重定向和重写功能，优化用户体验和SEO。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-project-diagram text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif text-gray-800">4. 概念关系图</h2>
            </div>
            
            <p class="text-gray-700 mb-6">以下图表展示了Nginx URL处理中重写与重定向的关系及常见应用场景：</p>
            
            <div class="bg-white p-6 rounded-lg">
                <div class="mermaid">
                    graph TD
                    A[客户端请求] --> B{Nginx处理}
                    B -->|重写| C[修改URL后继续处理]
                    B -->|重定向| D[返回新URL给客户端]
                    C --> E[内部处理请求]
                    D --> F[客户端发起新请求]
                    E --> G[返回响应]
                    F --> B

                    subgraph "URL重写"
                    C
                    E
                    end

                    subgraph "URL重定向"
                    D
                    F
                    end

                    style A fill:#f0f9ff,stroke:#4299e1
                    style B fill:#ebf8ff,stroke:#3182ce
                    style C fill:#e6fffa,stroke:#38b2ac
                    style D fill:#fff5f5,stroke:#f56565
                    style E fill:#e6fffa,stroke:#38b2ac
                    style F fill:#fff5f5,stroke:#f56565
                    style G fill:#f0f9ff,stroke:#4299e1
                </div>
            </div>
            
            <div class="mt-8 grid md:grid-cols-3 gap-6">
                <div class="bg-white p-4 rounded-lg border border-blue-100">
                    <h4 class="font-bold text-blue-600 mb-2 flex items-center">
                        <i class="fas fa-pen-fancy mr-2"></i> URL重写特点
                    </h4>
                    <ul class="text-sm text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>内部处理，客户端无感知</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>适用于SEO优化</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>使用<code class="bg-gray-100 px-1 py-0.5 rounded">rewrite</code>指令</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white p-4 rounded-lg border border-purple-100">
                    <h4 class="font-bold text-purple-600 mb-2 flex items-center">
                        <i class="fas fa-directions mr-2"></i> URL重定向特点
                    </h4>
                    <ul class="text-sm text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>客户端发起新请求</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>适用于网站迁移</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>使用<code class="bg-gray-100 px-1 py-0.5 rounded">return</code>指令</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white p-4 rounded-lg border border-green-100">
                    <h4 class="font-bold text-green-600 mb-2 flex items-center">
                        <i class="fas fa-lightbulb mr-2"></i> 最佳实践
                    </h4>
                    <ul class="text-sm text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>HTTPS强制跳转使用301</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>临时维护使用302</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-2 mt-0.5"></i>
                            <span>测试无误后再使用permanent</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-6 text-center">
            <h3 class="text-xl font-bold mb-4">技术小馆</h3>
            <p class="mb-6">探索技术的无限可能</p>
            <div class="flex justify-center space-x-4 mb-6">
                <a href="http://www.yuque.com/jtostring" class="hover:text-blue-400 transition duration-300">
                    <i class="fas fa-globe text-xl"></i>
                </a>
            </div>
            <p class="text-sm">
                &copy; 2023 技术小馆 | 
                <a href="http://www.yuque.com/jtostring" class="hover:text-blue-400 transition duration-300">yuque.com/jtostring</a>
            </p>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```